//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "PathMultiAssetOption.h"
using namespace Cephei::QL::Experimental::Mcbasket;
#include <gen/QL/Experimental/Mcbasket/PathPayoff.h>
#include <gen/QL/PricingEngine.h>
#include <gen/QL/Instrument.h>
using namespace Cephei::QL;
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::CPathMultiAssetOption (boost::shared_ptr<QuantLib::PathMultiAssetOption>& childNative, Object^ owner) : CInstrument(CPathMultiAssetOption::typeid)
{
#ifdef HANDLE
	_phPathMultiAssetOption = NULL;
#endif
	_ppPathMultiAssetOption = &childNative;
    _ppInstrument = new boost::shared_ptr<QuantLib::Instrument> (boost::dynamic_pointer_cast<QuantLib::Instrument> (*_ppPathMultiAssetOption));
}
Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::CPathMultiAssetOption (QuantLib::PathMultiAssetOption& childNative, Object^ owner) : CInstrument(CPathMultiAssetOption::typeid)
{
#ifdef HANDLE
	_phPathMultiAssetOption = NULL;
#endif
	_ppPathMultiAssetOption = new boost::shared_ptr<QuantLib::PathMultiAssetOption> (&childNative);
    _ppInstrument = new boost::shared_ptr<QuantLib::Instrument> (boost::dynamic_pointer_cast<QuantLib::Instrument> (*_ppPathMultiAssetOption));
    _PathMultiAssetOptionOwner = owner;
    _InstrumentOwner = owner;
}

Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::CPathMultiAssetOption (CPathMultiAssetOption^ copy) : CInstrument(CPathMultiAssetOption::typeid)
{
#ifdef HANDLE
	_phPathMultiAssetOption = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppPathMultiAssetOption = new boost::shared_ptr<QuantLib::PathMultiAssetOption> (copy->GetShared());
        _ppInstrument = new boost::shared_ptr<QuantLib::Instrument> (boost::dynamic_pointer_cast<QuantLib::Instrument> (*_ppPathMultiAssetOption));
    }
}
Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::CPathMultiAssetOption (System::Type^ t) : CInstrument(CPathMultiAssetOption::typeid)
{
#ifdef HANDLE
	_phPathMultiAssetOption = NULL;
#endif
	if (!t->IsSubclassOf(CPathMultiAssetOption::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::CPathMultiAssetOption (QuantLib::Handle<QuantLib::PathMultiAssetOption>& childNative, Object^ owner)  : CInstrument(CPathMultiAssetOption::typeid)
{
	_phPathMultiAssetOption = &childNative;
	_ppPathMultiAssetOption = &static_cast<boost::shared_ptr<QuantLib::PathMultiAssetOption>>(childNative.currentLink());
    _ppInstrument = new boost::shared_ptr<QuantLib::Instrument> (boost::dynamic_pointer_cast<QuantLib::Instrument> (*_ppPathMultiAssetOption));
    _PathMultiAssetOptionOwner = owner;
}
Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::CPathMultiAssetOption (QuantLib::Handle<QuantLib::PathMultiAssetOption> childNative)  : CInstrument(CPathMultiAssetOption::typeid)
{
	_phPathMultiAssetOption = &childNative;
	_ppPathMultiAssetOption = &static_cast<boost::shared_ptr<QuantLib::PathMultiAssetOption>>(childNative.currentLink());
    _ppInstrument = new boost::shared_ptr<QuantLib::Instrument> (boost::dynamic_pointer_cast<QuantLib::Instrument> (*_ppPathMultiAssetOption));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::CPathMultiAssetOption (QuantLib::PathMultiAssetOption childNative)  : CInstrument(CPathMultiAssetOption::typeid)
{
#ifdef HANDLE
	_phPathMultiAssetOption = NULL;
#endif
	_ppPathMultiAssetOption = new boost::shared_ptr<QuantLib::PathMultiAssetOption> (new QuantLib::PathMultiAssetOption (childNative));
    _ppInstrument = new boost::shared_ptr<QuantLib::Instrument> (boost::dynamic_pointer_cast<QuantLib::Instrument> (*_ppPathMultiAssetOption));
}
#endif

Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::~CPathMultiAssetOption ()
{
    if (_ppPathMultiAssetOption != NULL)
    {
	    delete _ppPathMultiAssetOption;
        _ppPathMultiAssetOption = NULL;
    }
}
Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::!CPathMultiAssetOption ()
{
    if (_ppPathMultiAssetOption != NULL)
    {
	    delete _ppPathMultiAssetOption;
    }
}
QuantLib::PathMultiAssetOption& Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::GetReference ()
{
    if (_ppPathMultiAssetOption == NULL) throw gcnew NativeNullException ();
	return **_ppPathMultiAssetOption;
}
boost::shared_ptr<QuantLib::PathMultiAssetOption>& Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::GetShared ()
{
    if (_ppPathMultiAssetOption == NULL) throw gcnew NativeNullException ();
	return *_ppPathMultiAssetOption;
}
QuantLib::PathMultiAssetOption* Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::GetPointer ()
{
    if (_ppPathMultiAssetOption == NULL) throw gcnew NativeNullException ();
	return &**_ppPathMultiAssetOption;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::PathMultiAssetOption>& Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::GetHandle ()
{
	if (_phPathMultiAssetOption == NULL)
	{
		_phPathMultiAssetOption = new Handle<QuantLib::PathMultiAssetOption> (*_ppPathMultiAssetOption);
	}
	return *_phPathMultiAssetOption;
}
#endif
bool Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::HasNative () 
{
	return (_ppPathMultiAssetOption != NULL);
}

Cephei::IVector<DateTime>^ Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::FixingDates::get ()
{
    try
    {
    	std::vector<QuantLib::Date> _rv = (std::vector<QuantLib::Date>)(*_ppPathMultiAssetOption)->fixingDates ( );   
        Cephei::IVector<DateTime>^ _nrv = gcnew CoVector<DateTime> (gcnew CDateTimeVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::IsExpired::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppPathMultiAssetOption)->isExpired ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Mcbasket::IPathPayoff^ Cephei::QL::Experimental::Mcbasket::CPathMultiAssetOption::PathPayoff::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::PathPayoff> _rv = (boost::shared_ptr<QuantLib::PathPayoff>)(*_ppPathMultiAssetOption)->pathPayoff ( );   
        Cephei::QL::Experimental::Mcbasket::CPathPayoff^ _nrv = gcnew Cephei::QL::Experimental::Mcbasket::CPathPayoff (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

